import { S } from '../../s';
import { IPSControlAction } from '../ipscontrol-action';
import { PSControlContainerImpl } from '../pscontrol-container-impl';
import { IPSLayout } from '../layout/ipslayout';
import { IPSPanelField } from './ipspanel-field';
import { IPSPanelItem } from './ipspanel-item';
import { IPSSysLayoutPanel } from './ipssys-layout-panel';
import { IPSSysPanel } from './ipssys-panel';

export class PSSysPanelImpl
  extends PSControlContainerImpl
  implements IPSSysPanel, IPSSysLayoutPanel
{
  protected allpspanelfields: IPSPanelField[];
  getAllPSPanelFields(): IPSPanelField[] | null {
    return (
      this.allpspanelfields ||
      (this.allpspanelfields = this.fillChildListModel(
        this.M.getAllPSPanelFields,
        S._186,
      ) as IPSPanelField[])
    );
  }

  findPSPanelField(objKey: any): IPSPanelField | null {
    return this.getPSModel5(
      S._186,
      this.getAllPSPanelFields(),
      objKey,
    ) as IPSPanelField;
  }

  get codeName(): string {
    return this.M.codeName;
  }

  get dataMode(): 0 | 1 | 2 | 3 | 4 | 5 {
    return this.M.dataMode != null ? this.M.dataMode : 0;
  }

  get dataName(): string {
    return this.M.dataName;
  }

  get dataTimer(): number {
    return this.M.dataTimer != null ? this.M.dataTimer : -1;
  }

  protected getpscontrolaction: IPSControlAction;
  getGetPSControlAction(): IPSControlAction | null {
    if (this.getpscontrolaction != null) return this.getpscontrolaction;
    const value = this.M.getGetPSControlAction;
    if (value == null) {
      return;
    }
    this.getpscontrolaction =
      this.getPSControlHandler().findPSControlHandlerAction(value);
    return this.getpscontrolaction;
  }

  get layoutMode():
    | 'TABLE'
    | 'TABLE_12COL'
    | 'TABLE_24COL'
    | 'FLEX'
    | 'BORDER'
    | 'ABSOLUTE' {
    return this.M.layoutMode;
  }

  protected pslayout: IPSLayout;
  getPSLayout(): IPSLayout | null {
    return (
      this.pslayout ||
      (this.pslayout = this.fillObjectModel(
        S._298,
        this.M.getPSLayout,
        S._2e8,
      ) as IPSLayout)
    );
  }

  get panelStyle(): string {
    return this.M.panelStyle;
  }

  get panelWidth(): number {
    return this.M.panelWidth != null ? this.M.panelWidth : 0.0;
  }

  protected rootpspanelitems: IPSPanelItem[];
  getRootPSPanelItems(): IPSPanelItem[] | null {
    return (
      this.rootpspanelitems ||
      (this.rootpspanelitems = this.fillChildListModel(
        this.M.getRootPSPanelItems,
        S._17c,
      ) as IPSPanelItem[])
    );
  }

  get layoutPanel(): boolean {
    return this.M.layoutPanel != null ? this.M.layoutPanel : false;
  }

  get mobilePanel(): boolean {
    return this.M.mobilePanel != null ? this.M.mobilePanel : false;
  }
  get cls(): string {
    return 'PSSysPanelImpl';
  }
  instanceof(cls: string): boolean {
    if (
      cls == S._214 ||
      cls == S._ae ||
      cls == S._255 ||
      cls == S._256 ||
      cls == S._257 ||
      cls == S._258
    )
      return true;
    return super.instanceof(cls);
  }
}
